<template>
  <div class="Tab">
    <div class="top">
      <router-link to="/about">◀</router-link>
      <van-search
        shape="round"
        background="#fff"
        placeholder="请输入搜索关键词"
      />
      <van-dropdown-menu>
        <van-dropdown-item v-model="value1" :options="option1" />
        <van-dropdown-item v-model="value2" :options="option2" />
      </van-dropdown-menu>
    </div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div class="content">
          <div class="shopcard" v-for="(item, index) in lodlist" :key="index" @click="handledetail(item.id)">
            <img :src="item.image" alt="" />
            <p>{{ item.store_name }}</p>
            <h3><span>￥</span>{{ item.price }}</h3>
            <p class="font">{{ "已售" + item.sales + item.unit_name }}</p>
          </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { gettable } from "../api/Table";
export default {
  data() {
    return {
      value1: 0,
      value2: "a",
      lodlist: [],
      loading: false,
      finished: false,
      p: 1, //分页页码
      option1: [
        { text: "全部商品", value: 0 },
        { text: "新款商品", value: 1 },
        { text: "活动商品", value: 2 },
      ],
      option2: [
        { text: "默认排序", value: "a" },
        { text: "好评排序", value: "b" },
        { text: "销量排序", value: "c" },
      ],
    };
  },
  methods: {
    loadData() {
      let { id } = this.$route.params;
      gettable(id).then((res) => {
        let films = res.data.data;
        if (this.p == 1) {
          this.lodlist = [
            ...this.lodlist, //原数据包
            ...films, //新数据
          ];
          this.p++;
        } else {
          this.finished = true; //没有更多数据了
        }
        this.loading = false;
      });
    },
    onLoad() {
      this.loadData();
    },
    handledetail(id) {
      this.$router.push({ path:`/detail/${id}` });
    },
    
  },
};
</script>

<style lang="less" scoped>
.top a {
  position: fixed;
  left: 0;
  top: 0;
}
.Tab {
  padding-bottom: 50px;
}
.top {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99;
}
.content {
  padding: 105px 1vh 0 1vh;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  background: #f5f5f5;
  a {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .font {
    font-size: 11px;
    color: #aaa;
  }
}
.shopcard {
  width: 21vh;
  height: 260px;
  margin-bottom: 10px;
  margin: 10px 2px;
  text-align: center;
  background: #fff;
  border-radius: 15px;
  img {
    width: 100%;
    height: 172px;
  }
  p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    padding: 2px 10px;
  }
  h3 {
    text-align: left;
    font-size: 18px;
    color: #ff448f;
    padding: 0px 10px;
    font-weight: 700;
    span {
      font-size: 13px;
    }
  }
}
</style>